<?

require_once $_SERVER['DOCUMENT_ROOT']."/../_lib/base/common.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.template.php";
require_once SITE_ROOT_PATH."_lib/classes/class.holidays.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.holiday_references.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.newsletter.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.destinations.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.photos.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.hotels.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.exchange_rates.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.holiday_special_offers.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.airports.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.reviews.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.lurls.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.breadcrumb.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.holiday_filters.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.tree.php";


	$airports = new airports();
	$hotels = new hotels();
	$destinations = new destinations();
	$holidays = new holidays();
	$holiday_references = new holiday_references();
	$photos = new photos();
	$reviews = new reviews();
	$lurls = new lurls();
	$breadcrumb = new breadcrumb();
	$holiday_filters = new holiday_filters();
	$specials = new holiday_special_offers();
	$tree = new tree();

	// Get holiday details from reference table
	$holiday_reference_id = $_GET['reference_id'];
	$cache['cache']['seconds'] = '600';
	$holiday_values = $holiday_references->get_holiday($holiday_reference_id, $cache);
	unset($cache);

	// Holiday expired
	if(!$holiday_values OR $holiday_filters->find_filtered_holiday($holiday_reference_id)){
		header("HTTP/1.0 301 Moved Permanently"); 
		header("location: /holidays/expired.html");
	}

	// Start session
	session_start();
	header("Cache-control: private");
	
	// Set the hotel name and resort to capital case
	$holiday_values['hotel_name'] = ucwords(strtolower($holiday_values['hotel_name']));
	$holiday_values['resort'] = ucwords(strtolower($holiday_values['resort']));
	
	$params = array();
	$params = $holiday_values;
    $params['supplier_code'] = 'mcs';
	// Check if its a special offer
	$sparams['reference_id'] = $holiday_reference_id;
	$special_values = $specials->get_special($sparams);
	unset($sparams);

	
	if(!empty($special_values[0]['hotel_tree_id'])){
		$params['tree_id'] = $special_values[0]['hotel_tree_id'];
		$special_offer = true;
	}
	$params['cache']['seconds'] = '2400';
	$lookup = $hotels->lookup_hotel($params);
	unset($params);
	
	// Set values
	$hotel_values = $lookup['hotel_values'];
	$resort_values = $lookup['resort_values'];
	$destination_values = $lookup['destination_values'];
	
	// Get photo url
	$lead_hotel_thumb_url = $tree->photo_url($hotel_values['main_photo']);
	
	// Get tree_id for breadcrumb
	if($hotel_values['tree_id']){
		$top_lineage = $hotel_values['lineage'];	
	}elseif($destination_values['tree_id']){
		$top_lineage = $destination_values['lineage'];
	}
	
	// Get Photos
	if($hotel_values['tree_id']){
		$cache['cache']['seconds'] = '2400';
		$hotel_photos = $photos->get_photos($hotel_values['tree_id'], $cache);
		unset($cache);
	}
	
	// Rating
	if(!$hotel_values['hotel_rating']){
		$hotel_values['hotel_rating'] = $holiday_values['hotel_rating'];
	}

	// Departure airport lookup
	$params['airport_code'] = $holiday_values['departure_airport'];
	$params['cache']['seconds'] = '2400';
	$departure_airport_values = $airports->get_airport($params);
	unset($params);
	
	// Destination airport lookup
	$params['airport_code'] = $holiday_values['destination_airport'];
	$params['cache']['seconds'] = '2400';
	$destination_airport_values = $airports->get_airport($params);
	unset($params);

	// Returning to airport lookup
	$params['airport_code'] = $holiday_values['return_airport'];
	$params['cache']['seconds'] = '2400';
	$return_airport_values = $airports->get_airport($params);
	unset($params);


	// PRICE DISPLAY 
	
	// If special then use the hotel ID
	if(!empty($special_values['hotel_tree_id'])){
	
		// Get the adult display price
		$display_price_adult = $holiday_values['price_adult'];

	}else{
	
		// See if the price has been filtered
		$mod_price = $holiday_filters->find_holiday_mod_price($holiday_reference_id, true);
		if($mod_price){
			$effective_price_adult = $mod_price['mod_price'];
			if($mod_price['price_adult']) $effective_price_adult = $mod_price['price_adult'];
			if($mod_price['price_child']) $effective_price_child = $mod_price['price_child'];
		}else{
			
			$effective_price_adult = $holiday_values['price_adult']; 
			$effective_price_child = $holiday_values['child_adult']; 
		}
	
		// Get the adult display price
		$params['price'] = $effective_price_adult;
		$params['departure_airport'] = $holiday_values['departure_airport'];
		$params['tour_op'] = $holiday_values['tour_op'];
		$display_price_adult = $holidays->display_price($params); 
		unset($params);
		
		// Get the child display price
		$params['price'] = $effective_price_child;
		$params['departure_airport'] = $holiday_values['departure_airport'];
		$params['tour_op'] = $holiday_values['tour_op'];
		$display_price_child = $holidays->display_price($params); 
		unset($params);
	
	}


	$params['reference_id'] = $holiday_reference_id;
	$url_string = $lurls->get_holiday_lurl($params);



	// Get the month of the departure 
	$tidy_number = str_replace("0", "", substr($holiday_values['departure_date'],2,2));
	$departure_month = date('F',mktime(0,0,0,(int)$tidy_number,1,2006));


	// Template
	$template = new template();	
	$template->title = $hotel_values['name'].", ".$resort_values['name'].", ".$destination_values['name']." holiday from ".$departure_airport_values['simple']." in ".$departure_month;
	$template->meta_keywords = $hotel_values['name'].", ".$resort_values['name'].", ".$destination_values['name']." holidays, budget travel,  from ".$departure_airport_values[0]['simple'].", ".$departure_month.", last minute, ".$holiday_values['nights']." nights, cheap holidays, from Ireland, last minute, lastminute";
	$template->meta_description = "Book Last minute holiday to ".$resort_values['name'].", ".$destination_values['name']." from ".$departure_airport_values[0]['simple']." in ".$departure_month.". Staying in ".$hotel_values['name']." hotel for ".$holiday_values['nights']." nights.";
	$template->meta_canonical = $url_string;
	$template->section_highlight = "holidays";
	$template->left_col = true;
	$template->search_tab = "holidays"; 
	$template->breadcrumbs_html = $breadcrumb->get_html_breadcrumb($top_lineage);
	$template->ld_head();


	if(!empty($hotel_values['tree_id'])){
		$params['tree_id'] = $hotel_values['tree_id'];
		$params['status'] = 'a';
		$params['cache']['seconds'] = '2400';
		$hotel_reviews = $reviews->get_review_average($params);
		if($hotel_reviews){
			$hotel_reviews_list = $reviews->get_reviews($params);
		}
		// Get LURL of the reviews
		$lurl_review_add = $lurls->get_hotel_review_add_lurl($params['tree_id']);
		// Get LURL of the reviews
		$lurl_review_read = $lurls->get_hotel_review_lurl($params['tree_id']);
		unset($params);
	}


?>







<h2 title="<?= $hotel_values['name'].", ".$resort_values['name'].", ".$destination_values['name'] ?>"><?= $hotel_values['name'].", ".$resort_values['name'].", ".$destination_values['name'] ?></h2>













<!-- Start hotel details -->
<div class="box_margin">

<div class="col_110">
<div class='thumb_cover_div'>
<? if($hotel_photos){ ?>
<a id="main-thumb-ref" href="#"><img src="<?= $lead_hotel_thumb_url ?>" alt="<?= $hotel_values['name'] ?>" class="thumb_image_100" /><img src="/images/thumb_cover_100_74.gif" class="thumb_cover" alt="<?= $destination['name'] ?>" /></a>
<? }else{ ?>
<img src="<?= $lead_hotel_thumb_url ?>" alt="<?= $hotel_values['name'] ?>" class="thumb_image_100" /><img src="/images/thumb_cover_100_74.gif" class="thumb_cover" alt="<?= $destination['name'] ?>" />
<? }?>
</div>
</div>


<div class="col_310">


<p class="title_big"><?= $hotel_values['name'] ?></p>
<p class="title_med"><?= $resort_values['name'].", ".$destination_values['name'] ?></p>



<!-- Start rating -->
<p class="margin_bottom_3"><? if($hotel_values['hotel_rating']) echo output_rating($hotel_values['hotel_rating'], "star", true); ?>&nbsp;</p>
<!-- End rating -->



<!-- Start review link -->
<? if($hotel_reviews){ ?>
<p class="no_margin"><?= output_rating($hotel_reviews['0']['overall'], "rate", true); ?> <a href="<?= $lurl_review_read ?>">Read reviews (<?= $hotel_reviews['0']['num_reviews'] ?>)</a></p>
<? }elseif(!empty($hotel_values['tree_id'])){ ?>
<p class="no_margin">This hotel has not been reviewed <a href="<?= $lurl_review_add ?>">Write a review</a></p>
<? } ?>
<!-- End review link -->






</div>






<div class="col_190">



<!-- Start send 2 + bookmark box -->
<div class="box_lb_190_cap">
<div class="box_lb_190_shoe">
<div class="padding_10">

<ul class="blank_list">
	<li class="link_fav"><a href="javascript:addToFavorites('<?= $template->title ?>', '<?= MAIN_SITE_ROOT.$_SERVER['REQUEST_URI'] ?>')">Bookmark this page</a></li>
</ul>

</div>
</div>
</div>
<!-- End send 2 + bookmark box -->






</div>

<div class="clearing"></div>



</div>
<!-- End hotel details -->























<!-- Star booking details -->


<h3 title="Holiday Details">Holiday Details</h3>




<!-- Start search criteria -->




<table>
<tr>
<td width="305">

<table class="aqua">
    <tr>
        <td width="110"><strong>Departing</strong></td>
        <td width="195">

<p><?= display_sabs_date($holiday_values['departure_date'],'l j F Y') ?><br/>


<?= $departure_airport_values[0]['simple']." (".$holiday_values['departure_airport'].") "; ?>

<? if($holiday_values['depart_dept_time']){ ?>
, Departs: <?= sabs_flight_time_2_std($holiday_values['depart_dept_time']); ?>
<? } ?>

<br />
<?= $destination_airport_values[0]['simple']." (".$holiday_values['destination_airport'].") "; ?>

<? if($holiday_values['arrive_dest_time']){ ?>
, Arrives: <?= sabs_flight_time_2_std($holiday_values['arrive_dest_time']); ?>
<? } ?>

</p>
        
        </td>
</tr>
<tr>
    <tr>
        <td><strong>Returning</strong></td>
        <td>
<?
// Check to see if the returning airport is the same
$alt_return_airport = false;
if($holiday_values['return_airport']!==''){
if($holiday_values['return_airport']!==$holiday_values['departure_airport']){
	$alt_return_airport = true;
}
}

?>
<p class="no_margin"><?= display_sabs_date($holiday_values['return_date'],'l j F Y') ?><br/>
<?= $destination_airport_values[0]['simple']." (".$holiday_values['destination_airport'].") "; ?>


<? if($holiday_values['depart_dest_time']){ ?>
, Departs: <?= sabs_flight_time_2_std($holiday_values['depart_dest_time']); ?>
<? } ?>

<br />
<?= $return_airport_values[0]['simple']." (".$holiday_values['return_airport'].") "; ?>

<? if($holiday_values['arrive_dept_time']){ ?>
, Arrives: <?= sabs_flight_time_2_std($holiday_values['arrive_dept_time']); ?>
<? } ?>

</p>

<?



if($alt_return_airport){
echo "<br /><span style='color:#ff0000;font-weight:bold; font-size: 13px;'>Please note</span> the return airport<br />
 differs from the outgoing airport.";
}
?>

        
        </td>
</tr>
</table>

</td>
<td width="305">

        
        
        
<table class="aqua">
<tr>
    <td width="120"><strong>Nights</strong></td>
    <td width="195"><?= $holiday_values['nights'] ?> nights</td>
<tr>
    <td><strong>Board Basis</strong></td>
    <td><?= $holidays->board_basis($holiday_values['board_basis']); ?></td>
</tr>
<tr>
        <td><strong>Adult price</strong></td>
        <td><span class="price_lrg">&euro;<?= $display_price_adult; ?></span><span class="price_asterix">*</span></td>
    </tr>
<? if($display_price_child) { ?>
<tr>
	<td><strong>Child price</strong></td>
    <td><span class="price_lrg">&euro;<?= $display_price_child; ?></span><span class="price_asterix">*</span></td>
</tr>
<? } ?>

<tr>
	<td colspan="2"><span class="price_terms">* Prices include <strong>Flights, Luggage, Transfers</strong> and <strong>Accommodation</strong>. Prices are per person and are based on the maximum number of people occupying the accommodation or per accommodation. Final pricing will be confirmed at time of booking as supplements may apply.</span></td>
</tr>
</table>

</td>
</tr>
</table>



<!-- End booking details -->


<br />




<?

// !$special_offer
if(1==1){
	
switch ($holiday_values['tour_op']) {
	case "SWY";

		$y = substr($holiday_values['departure_date'],0,2);
		$m = substr($holiday_values['departure_date'],2,2);
		$d = substr($holiday_values['departure_date'],4,2);
		$departure_date_timestamp = mktime(0, 0, 0, $m, $d, $y);
		$eight_weeks_future_timestamp = strtotime("+55 days");
	
		if($departure_date_timestamp<$eight_weeks_future_timestamp){
			require_once SITE_ROOT_PATH."/_lib/html/holiday_book_online_form.php";
		}


	break;
	case "TFL";

		$y = substr($holiday_values['departure_date'],0,2);
		$m = substr($holiday_values['departure_date'],2,2);
		$d = substr($holiday_values['departure_date'],4,2);
		$departure_date_timestamp = mktime(0, 0, 0, $m, $d, $y);
		$eight_weeks_future_timestamp = strtotime("+55 days");
	
		if($departure_date_timestamp<$eight_weeks_future_timestamp){
			require_once SITE_ROOT_PATH."/_lib/html/holiday_book_online_form.php";
		}

	break;

}

}

?>


<!-- Start Book now box -->


<div class="box_book_now">
<div class="box_book_now_inner">
<div class="box_book_now_phone"><img src="/images/call_now_text_roi.gif" alt="Call Now 0818 212 313" /></div>
<div class="box_book_now_phone_int">Eire +353 (0)1 6853015</div>
<div class="box_book_now_ref">Ref:&nbsp;&nbsp;P.<?= $holiday_reference_id ?></div>

<div class="box_book_now_hours">

	<table>
	  <tr>
		  <td width="105"><strong class="white">Opening Hours</strong></td>
		  <td width="180">
		  <table>
		  <tr>
		  <td width="90">Monday - Friday</td>
		  <td width="90">9 - 7pm</td>
		  </tr>
		  <tr>
		  <td>Saturday</td>
		  <td>10 - 2pm</td>
		  </tr>
		  </table>
		  </td>
	  </tr>
	</table>
</div>
</div>
</div>



<!-- End Book now box -->




<br />








<? include SITE_ROOT_PATH."/_lib/html/hotel_details_tabs.php"; ?>




<br />



<? include SITE_ROOT_PATH."/_lib/html/pricing_terms.php"; ?>
<!-- Google Code for Late Deals Offers Page Remarketing List -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1065994132;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "aY3UCMDF4QIQlI-n_AM";
var google_conversion_value = 0;
/* ]]> */
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1065994132/?label=aY3UCMDF4QIQlI-n_AM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>



<!-- Google Code for Holiday Lookup Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1065994132;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "iETgCIjYnAIQlI-n_AM";
var google_conversion_value = 0;
if (0.14) {
  google_conversion_value = 0.14;
}
/* ]]> */
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1065994132/?value=0.14&amp;label=iETgCIjYnAIQlI-n_AM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>
<? 		$template->ld_foot(); ?>